﻿Imports Data

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Try
            Dim usuario As String = If(txtUsuario.Text IsNot Nothing, txtUsuario.Text, String.Empty)
            Dim password As String = If(txtPassword IsNot Nothing, txtPassword.Text, String.Empty)


            If (String.IsNullOrEmpty(usuario) <> True And String.IsNullOrEmpty(password) <> True) Then
                Dim usuario_validar As Empleados = Me.Validar(usuario, password)
                If usuario_validar IsNot Nothing Then
                    If usuario_validar.id_estado <> 5 Then
                        MsgBox("Usuario Invalido, porfavor comunicarse con el Administrador")
                    Else
                        Dim form As New Menu(String.Format("{0} {1}", usuario_validar.nombre, usuario_validar.apellido_paterno), usuario_validar.id)
                        form.Show()
                        Me.Hide()
                    End If
                Else
                    MsgBox("Usuario o Contraseña Incorrecto")
                End If
            Else
                MsgBox("Usuario o Contraseña no ingresado")
            End If
        Catch ex As Exception
            Debug.Print(ex.Message)
        End Try
    End Sub



    Private Function Validar(ByVal usuario As String, ByVal password As String) As Empleados
        Try
            Using db As New SerigraphicaDBDataContext
                Dim user As Empleados = db.Empleados.Where(Function(p) p.password = password And p.usuario = usuario).Select(Function(p) p).FirstOrDefault
                Return user
            End Using
        Catch ex As Exception
            Debug.Print("Error en la clase: {0}", Me.Name)
            Return Nothing
        End Try
    End Function
End Class
